//定义一个多属性的类
class ContentForTask
{
public:
  ContentForTask(String iname, String igender, int iage):name(iname), gender(igender), age(iage)
  {

  };
  String name;//人名
  String gender;//性别
  int age;//年龄
};
//定义一个多属性的结构体
struct Book
{
  String name;//书名
  String author;//作者
  int price;//售价
};
//#define useClass//选择使用类还是结构体
void serialTask(void* content)
{
  Serial.println("serialTask begin.");
#ifdef useClass
  ContentForTask* contentObj = (ContentForTask*)content;
  while(1)
  {
    Serial.print("name is ");
    Serial.println(contentObj->name);
    Serial.print("gender is ");
    Serial.println(contentObj->gender);
    Serial.print("age is ");
    Serial.println(contentObj->age);
    vTaskDelay(2000/portTICK_RATE_MS);
  }
#else
  Book* book = (Book*)content;
  while(1)
  {
    Serial.print("name is ");
    Serial.println(book->name);
    Serial.print("author is ");
    Serial.println(book->author);
    Serial.print("price is ");
    Serial.println(book->price);
    vTaskDelay(2000/portTICK_RATE_MS);
  }
#endif
}
//LED闪烁任务，参数为闪烁的延时
void ledBlinkTask(void* delayms)
{
  Serial.println("ledBlinkTask begin.");
  bool ledState = false;
  pinMode(2, OUTPUT);
  while(1)
  {
    digitalWrite(2, ledState);
    ledState = !ledState;
    vTaskDelay(*(int*)delayms/portTICK_RATE_MS);
  }
}
int delayms = 500;
void setup()
{
  Serial.begin(115200);
  
#ifdef useClass
  ContentForTask* content = new ContentForTask("Tom", "men", 20);
  xTaskCreate(serialTask, "serialTask", 1024, (void*)content, 1, nullptr);
#else
  Book* book = new Book{"The Old Man and the Sea", "Hemingway", 99};
  xTaskCreate(serialTask, "serialTask", 1024, (void*)book, 1, nullptr);
#endif
  
  xTaskCreate(ledBlinkTask, "ledBlinkTask", 1024, (void*)&delayms, 1, nullptr);

}

void loop() {
  // put your main code here, to run repeatedly:

}
